<template>
  <div class="favor-top">
    <div class="img">
      <img :src="item.defaultPicture" alt="">
    </div>

    <div  class="score">
      <div class="left"> {{ overall }}分</div>
      <div class="right"> {{ scoreTitle }}</div>
    </div>

    <div class="tab">
      <div class="logo">
        <img :src="logoUrl" alt="">
      </div>
      <div class="rate">
        <van-rate v-model="rate" icon="like" void-icon="like-o" count="1" @click="rateChange" readonly/>
      </div>
      <div class="totalCount">
        <van-icon name="chat-o" :badge="totalCount" />
      </div>
    </div>
  </div>
</template>

<script setup>
import {ref,onUnmounted} from "vue"
import useFavorStore from '@/stores/modules/favor';

const favorStore = useFavorStore()

const props =  defineProps({
  item:{
    type:Object,
    default:() => ({})
  },
  index:{
    type:Number,
    default:0
  }
})
const scoreTitle = props.item.commentBriefForCD.scoreTitle
const overall = props.item.commentBriefForCD.overall
const totalCount = props.item.commentBriefForCD.totalCount
const logoUrl = props.item.logoUrl


const rate =ref(1)
function rateChange(){
  rate.value = Math.abs(1-rate.value)
}

onUnmounted(()=>{
  if (!rate.value) favorStore.changeSelect(props.index)
})
</script>

<style lang="less" scoped>
.favor-top {
  position: relative;
  img {
    width: 100%;
  }

  .score {
    position: absolute;
    bottom: 20px;
    left: 25px;
    display: flex;
    justify-content: space-around;
    align-content: center;
    background-color: #f2f3f4;
    border-radius: 10px;
    font-size: 4px;
    .left {
      padding:2px 5px;
    }
    .right {
      padding:2px 5px;
      color: #ccc;
    }
  }

  .tab {
    position: absolute;
    top: 20px;
    right: 10px;
    .logo {
      img {
        width: 30px;
        border-radius: 50%;
      }
    }
    .rate {
      margin-top: 15px;
      text-align: center;
    }
    .totalCount {
      margin-top: 10px;
      text-align: center;
      ::v-deep(.van-badge) {
        font-size: 5px;
      }
    }
  }
}
</style>